﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AjaxControlToolkit;
using System.Net.Mail;

public partial class Front_UserControl_PasswordRecovery : System.Web.UI.UserControl {
    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
        }
    }

    protected void lnkbtnCancel_Click(object sender, EventArgs e) {
        Response.Redirect("SignUp.aspx");
    }

    protected void PayButton_Click(object sender, EventArgs e) {
        try {
            string UserID = "";
            string FName = "";
            var PasswordRecovery = new DealesDataContext();
            var DealDesp = PasswordRecovery.Select_UserIDByEmail(txtEmail.Text);
            foreach (var item in DealDesp) {
                UserID = item.UserId.ToString();
                FName = item.FName.ToString();
            }
            Session["Email"] = txtEmail.Text;
            System.Collections.Specialized.ListDictionary replacements = new System.Collections.Specialized.ListDictionary();
            string EmailText = 
                "<table width=\"50%\" style=\"border-color: #008800; border-width: 15px; border-style: solid;\">" +
                    "<tr><td align=\"center\"><br /><img src=\"http://www.zupons.com/Images/logo.png\" /><br /><br /></td></tr>" +
                    "<tr><td><hr /></td></tr>" + 
                    "<tr><td><b>Hi " + FName + ",</b><br /><br /></td></tr>" + 
                    "<tr style=\"border-color: #80FE80; border-width: 15px; border-style: solid; background: #FFFF99;\" align=\"center\">" + 
                        "<td><a href=\"http://www.zupons.com/PasswordReset.aspx?UserID=" + UserID + "\" runat=\"server\">Click here to reset your password</a><br/><br/></td>" + 
                    "</tr>" + 
                    "<tr><td align=\"left\"><br />Note: We received a request to reset your password. If you didn't make this request,simply ignore this email.</td></tr>" + 
                    "<tr><td><hr /></td></tr>" + 
                    "<tr><td align=\"center\">Thanks,<br />Zupons <a href=\"http://www.zupons.com\" runat=\"server\">http://www.zupons.com</a><br /><br /></td></tr>" + 
                    "<tr style=\"border-color: #80FE80; border-width: 15px; border-style: solid; background: #ddedcc;\" align=\"center\">" + 
                        "<td><br />Need Help ? Have FeedBack ? Feel Free To <a href=\"http://www.zupons.com/ContactUs.aspx\" runat=\"server\">ContactUs</a><br /><br />Delivered by <a href=\"http://www.zupons.com\" runat=\"server\">Zupons</a></td>" + 
                    "</tr>" + 
                "</table>";
            //replacements.Add("<%UserName%>", EmailText);
            //System.Net.Mail.MailMessage confirmation = Mailer.CreateMessage(new System.Web.UI.Control() as WebControl, Mailer.MessageTemplate.NewOrder, replacements, txtEmail.Text, "Reset Your Password");
            // Mailer.InternalSend(confirmation, false);

            MailMessage Mail = new MailMessage();
            MailAddress ma = new MailAddress("mail@zupons.com", "Zupons");
            Mail.From = ma;
            Mail.To.Add(txtEmail.Text);
            Mail.Subject = "Reset Your Password";
            Mail.Body = EmailText;
            Mail.IsBodyHtml = true;
            try {
                SmtpClient smtpMailObj = new SmtpClient();
                smtpMailObj.Host = "mail.zupons.com";
                smtpMailObj.Send(Mail);
                //Response.Write("Your Message has been sent successfully");
            } catch (Exception ex) {
                Response.Write("Message Delivery Fails");
            }

            Response.Redirect("SendPasswordReset.aspx");
        } catch (Exception ex) {
        }
    }
}
